<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php include_once 'functions.php'; ?>
        <?php
        
            $cpid=$_POST['cpid'];
            $cnum=$_POST['cnum'];
            $cuid=$_COOKIE['cuid'];
            echo "$cuid,$cpid,$cnum<br>";
         
            $link=  mysqli_connect("localhost", "root","");//打开一个数据库的连接
            mysqli_select_db($link, "nhcar");//选择连接某个数据库
            mysqli_set_charset($link, "utf8");//设置数据库连接的字符集 
               
            $sql="INSERT INTO cart (cpid,cuid,num)VALUES($cpid,$cuid,$cnum);";
            echo "$sql<br>";
                
            $result=mysqli_query($link, $sql);
            var_dump($result); 
            echo"<br>";   
//          exit();
        
             if($result){
                go_forward("添加购物车成功！","cart.php");
            }else{
                go_forward("添加购物车失败！","product.php?id=$gid");
            }
        ?>
    </body>
</html>
